PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Repeat (number) Times

The Repeat (number) Times form of the Repeat statement repeats a group of statements a specified number of times.

SYNTAX
repeat integer [ times ]
    [ statement ]...
end [ repeat ]

where

integer is an integer that specifies the number of times to repeat the statements in the body of the loop. The word times after integer is optional.

statement is any AppleScript statement.

EXAMPLE

The following example numbers the paragraphs of a document with the Repeat (number) Times form of the Repeat statement.

tell document "Simple" of application "AppleWorks"
    set numParagraphs to (count paragraphs of text body)
    set paragraphNum to 1
    repeat numParagraphs times
        set paragraph paragraphNum of text body ¬
            to (paragraphNum as string) ¬
            & " " & paragraph paragraphNum of text body
        set paragraphNum to paragraphNum + 1
    end repeat
end tell

© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)